using System;
using System.Collections;

namespace Sedna.Core.Controller.Configurations
{
	public class NameValuePairCommandArgumentGenerator : ICommandArgumentGenerator
	{
		private IDictionary name2value;

		private ICommandArgumentGenerator next = CommandConfiguration.EmptyStringCommandArgumentGenerator.Instance;

		public IDictionary Name2value
		{
			set { name2value = value; }
		}

		public ICommandArgumentGenerator Next
		{
			set { next = value; }
		}

		public string GenerateCommandArguments(ICommandConfiguration configuration, IExecutionContext executionContext)
		{
			return BuildArguments() + next.GenerateCommandArguments(configuration, executionContext);
		}

		private string BuildArguments()
		{
			string result = string.Empty;
			for(IDictionaryEnumerator en = name2value.GetEnumerator(); en.MoveNext();)
			{
				result += String.Format("{0}={1};", en.Key, en.Value);
			}
			return result;
		}
	}
}
